package com.starchen.optimalselection.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starchen.optimalselection.admin.mapper.AdminRoleMapper;
import com.starchen.optimalselection.admin.model.AdminRole;
import com.starchen.optimalselection.admin.service.AdminRoleService;
import com.starchen.optimalselection.common.model.QueryParamsForm;
import com.starchen.optimalselection.common.model.ResultPage;
import com.starchen.optimalselection.common.utils.PageUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author daxilong
 * @date 2025/3/21 10:38
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements AdminRoleService {

    @Override
    public ResultPage getPage(QueryParamsForm queryParamsForm) {
        String key =  queryParamsForm.getKeyword();
        QueryWrapper<AdminRole> queryWrapper = new QueryWrapper<>();
        if(StringUtils.hasText(key)){
            queryWrapper.like("role_name",key);
        }

        IPage<AdminRole> page = baseMapper.selectPage(PageUtils.getPage(queryParamsForm.getPageIndex(),queryParamsForm.getPageSize()), queryWrapper);
        return new ResultPage(page);
    }

}
